package com.tuling.bio;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Server {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket=null;
        try {
            serverSocket = new ServerSocket();
            serverSocket.bind(new InetSocketAddress(9999));

            while (true) {
                Socket socket = serverSocket.accept();
                System.out.println("收到socket！");
                InputStream inputStream = socket.getInputStream();

                byte[] bytes = new byte[1024];
                while (inputStream.read(bytes) != -1) {
                    System.out.println(new String(bytes, StandardCharsets.UTF_8));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            serverSocket.close();
        }
    }
}
